<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>设备管理</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<jsp:include page="../resource.jsp"></jsp:include>
<style type="text/css">
   #regionsEditor{
     background:#E7EEF8  url(../images/main_bottom_bg.jpg) bottom right no-repeat;
   }
   .deviceTree{
     width : 450px;
   }
</style>
<script type="text/javascript">
$(function(){
	  $('#regionsEditor').omDialog({
		  autoOpen: false,
		  height: 320,
		  width : 480
	  });
	  //添加
	  $('#regionsadd').click(function(){
		  var treeNode = $("#deviceTree").omTree("getSelected");
		  $('#regionsForm').resetForm(); //重置表单
		  $('CId').val('');
		  $('#pText').parent().parent().show();
          if($('#regionsroot').hasClass('selected')){
        	  $('#regionsEditor').omDialog('open');
    		  $('#pRId').val('0');
    		  $('#pText').val('根节点');
          }else{
			  $('#regionsEditor').omDialog('open');
			  $('#pRId').val(treeNode.id);
			  $('#pText').val(treeNode.text);
	      }
	  });
	  
	  $('#regionsroot').click(function(){
		  $(this).parent().addClass('selected');
		  $('#deviceTree').find('span.selected').removeClass('selected');
	  });
	  
	  //修改
	  $('#regionsmodify').click(function(){
		  var treeNode = $("#deviceTree").omTree("getSelected");
		  if(treeNode == undefined){
        	  $.omMessageBox.alert({content:'请您选择修改的节点'});
        	  return ;
          }
		  $('#regionsEditor').omDialog('open');
		  $.ajax({
			  url: "regions!findRegions.do",
			  data : {regionsId : treeNode.id},
			  dataType : 'json',
			  success: function(data){
				  $('#pText').parent().parent().hide();
				  $('#RCnName').val(data[0].name);
				  $('#RpinYin').val(data[0].pinYin);
				  $('#RId').val(data[0].id);
				  $('#RabbName').val(data[0].abbreviation);
				  $('#RLinkUrl').val(data[0].linkUrl );
				  $('#RIsleaf').val(data[0].isleaf?1:0);
				  $('#RSort').val(data[0].sort );
			  }
			});
	  });
	  
	  //删除
	  $('#regionsdelete').click(function(){
		  var treeNode = $("#deviceTree").omTree("getSelected");
		  if(treeNode == undefined){
        	  $.omMessageBox.alert({content:'请您选择删除的节点'});
        	  return ;
          }
		  $.omMessageBox.confirm({
	           title:'确认删除',
	           content:'删除数据后其子节点数据也会删除，请确认！',
	           onClose:function(v){
	               if(v){
	            	   $(this).omAjaxSubmit({
		         			  url : 'regions!deleteRegions.do',
		         			  data : {regionsId : treeNode.id},
		         			  success : function(data){
		         				  if(data == '1'){ 
		         					  $.omMessageTip.show({timeout : 2000,content : '删除成功！'});
		         					  $('#deviceTree').omTree('remove',treeNode);
		         				  }else{
		         					  $.omMessageTip.show({timeout : 2000,content : '删除失败！',type : 'error'});
		         				  }
		         			  }
		         		  });
	               }
	           }
	       });
	  });
	  
	  $('#deviceTree').omTree({
          dataSource : 'regions!queryList.do',
          widht : 350,
          onClick : function(){
        	  $('#regionsroot').parent().removeClass('selected');
          }
      });
	  $('#regionssubform').omButton({width : 100});
	  
	  var options  = {
		  url : 'regions!saveRegions.do',
          success : function(data){
             	if(data != '0'){  //TODO 刷新到指定的节点，目前是整个树刷新
             		//var target = $('#deviceTree').omTree('getParent',$('#deviceTree').omTree('getSelected'));
                 	if($('#RId').val() > 0){ //修改
              			 $('#deviceTree').omTree('refresh');
                 	}else{ //新增
                 		$('#deviceTree').omTree('refresh');
                 	}
                 	$('#regionsForm').omAjaxSubmit({resetForm: true});
                 	$('#regionsEditor').omDialog('close');
                 	$.omMessageTip.show({timeout : 2000,content : '保存成功！'});
             	}else{
             		$.omMessageTip.show({timeout : 2000,content : '保存失败！',type : 'error'});
             	}
          }
	  };
	  $('#regionsForm').submit(function() {
          $(this).omAjaxSubmit(options);
          return false;//返回false,阻止浏览器默认行为
      });
});
</script>
  </head>
  <body>
    <div class="right clear" >
		<div class="toolbar mar">
		         <a href="#" class="rbutton" id="regionsadd"><span><img src="../images/add.gif" width="14" height="14" /><ins>添加</ins></span></a>
		         <A  class="line"></A>
		         <a href="#" class="rbutton" id="regionsmodify"><span><img src="../images/add.gif" width="14" height="14" /><ins>修改</ins></span></a>
		         <A  class="line"></A>
		         <a href="#" class="rbutton" id="regionsdelete"><span><img src="../images/del.gif" width="14" height="14" /><ins>删除</ins></span></a>
		</div>
		<div class="deviceTree">
		  <ul class="om-tree om-widget">
		     <li class="om-tree-node collapsable">
		        <div class="hitarea om-tree-node-hitarea -hitarea collapsable-hitarea"></div>
		        <span class="folder selected"><a href="#"  id="regionsroot">设备菜单</a></span>
		        <ul id="deviceTree"></ul>
		     </li>
		  </ul>
		</div>
   </div>
   
   <div id="regionsEditor" title="编辑菜单" style="display: none;">
     <form id="regionsForm" method="post">
          <table width="100%" border="0" class="grid_layout" cellspacing="0">
             <tr>
               <td width="10%" align="right"><span class="color_red">*</span>父节点：</td>
               <td width="28%" colspan="3">
                 <input type="text" name="pRId" id="pRId" style="display: none;"/>
                 <input type="text" name="RId" id="RId" style="display: none;"/>
                 <input type="text" name="pText" id="pText" class="input_text" readonly="readonly"/>
               </td>
             </tr>
             <tr>
               <td align="right">中文名称：</td>
               <td colspan="3"><input type="text" name="RCnName" id="RCnName" class="input_text"  /></td>
             </tr>
             <tr>
               <td width="10%" align="right">拼音：</td>
               <td width="28%" colspan="3"><input type="text" id="RpinYin" name="RpinYin" class="input_text" /></td>
             </tr>
             <tr>
               <td width="10%" align="right">拼音缩写：</td>
               <td width="28%" colspan="3"><input type="text" id="RabbName" name="RabbName" class="input_text" /></td>
             </tr>
             <tr>
               <td align="right">链接地址：</td>
               <td colspan="3"><input type="text" name="RLinkUrl" id="RLinkUrl"  class="input_text"  /></td>
             </tr>
             <tr>
               <td align="right">是否叶子节点：</td>
               <td colspan="3">
               <select name="RIsleaf" id="RIsleaf" class="input_slelct">
                  <option value="1">是</option>
                  <option value="0">否</option>
               </select>
             </tr>
             <tr><td colspan="4" align="center"><button id="regionssubform" type="submit"> 保&nbsp;&nbsp;&nbsp;&nbsp;存 </button></td></tr>
           </table>
         </form>
   </div>
  </body>
</html>
